Enemy22 = Enemy.extend ({

	init: function(context, imagePath) {

		this._super(context, imagePath);
		this.scale =0.30;
		this.curentPositionEnemy = [1140, 753];
		this.w = 10;
		this.h = 10;
		this.firstShootFromEnemy = 1000;
		this.secondShootFromEnemy = 2200;
	},
	
	drawWalkEnemy: function() {
		var self = this;
		
		var frame = self.frameIndex;
		this.clear(self.curentPositionEnemy[0], self.curentPositionEnemy[1]);
		this.context.save();
		this.context.scale(self.scale, self.scale);
		this.context.drawImage(self.img, ( frame * 100), 0,
								100, 154,
								self.curentPositionEnemy[0], self.curentPositionEnemy[1],
								(100 + self.w), ( 150 + self.h));
		this.context.restore();
	},
	
	drawShooterEnemy: function() {
		var self = this;
		this.clear(self.curentPositionEnemy[0], self.curentPositionEnemy[1]);
		this.context.save();
		this.context.scale(self.scale, self.scale);
		this.context.drawImage(self.img, 500 , 0,
								100, 154,
								self.curentPositionEnemy[0], self.curentPositionEnemy[1],
								(100 + self.w) , (154 + self.h));
		this.context.restore();
	},
	
	drawDeadEnemy: function() {;
		var self = this;	
		var frame = self.frameIndex;
		this.clear(self.curentPositionEnemy[0], self.curentPositionEnemy[1]);
		this.context.save();
		this.context.scale(self.scale, self.scale);
		this.context.drawImage(self.img, ( frame * 100) , 154,
								100, 154,
								self.curentPositionEnemy[0], self.curentPositionEnemy[1],
								(100 + self.w) , (154 + self.h));
		this.context.restore();
	},
	
	clear: function(x, y) {
		this.context.save();
		this.context.scale(this.scale, this.scale);
		this.context.clearRect((x-10), (y-10), (130 + this.w), (190 + this.h));
		this.context.restore();
	},
	
	walkEnemy: function() {
		var self = this;
		self.interval = setInterval(function() {
			self.drawWalkEnemy();
			self.curentPositionEnemy[0] += 4;
			self.curentPositionEnemy[1] += 4;
			self.w += 12;
			self.h += 12;
			self.frameIndex ++;
	        if (self.frameIndex >= self.numberOfFrame-1) {	
				clearInterval(self.interval);
				self.drawWalkEnemy();
	        } 
		}, 1000/9);
	},
	
	shooterEnemy: function(flag) {
		var self = this;
		if(flag){
			this.shoot1 = setTimeout(function() {
				self.drawShooterEnemy();
			}, self.firstShootFromEnemy);
			this.stayEnemy1 = setTimeout(function() {
				self.drawWalkEnemy();
			}, (self.firstShootFromEnemy + 300));
			this.shoot2 = setTimeout(function() {
				self.drawShooterEnemy();
			}, self.secondShootFromEnemy);
			this.stayEnemy2 = setTimeout(function() {
				self.drawWalkEnemy();
			}, (self.secondShootFromEnemy + 200));
			
			this.clearEnemy = setTimeout(function() {
				self.clear((self.curentPositionEnemy[0]), (self.curentPositionEnemy[1]));
			}, (self.secondShootFromEnemy + 800));
		} else {
			clearTimeout(this.shoot1);
			clearTimeout(this.stayEnemy1);
			clearTimeout(this.shoot2);
			clearTimeout(this.stayEnemy2);
			clearTimeout(this.clearEnemy);
			
		}
		
		
	},
});